package com.chenfei.poi.controller.device;

import com.chenfei.poi.domain.DeviceCirculation;
import com.chenfei.poi.request.device.DeviceReq;
import com.chenfei.poi.response.BaseResp;
import com.chenfei.poi.response.device.DeviceDetailResp;
import com.chenfei.poi.response.device.DeviceResp;
import com.chenfei.poi.service.DeviceService;
import com.chenfei.poi.utils.PoiUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @author chenfei
 * @description
 * @since 2018/2/5
 */
@RestController
@RequestMapping(value = "/service/device")
@Slf4j
@Api(value = "设备控制器",description="设备控制器")
public class DeviceController {

    @Autowired
    DeviceService deviceService;

    @ApiOperation(value = "导入设备信息", httpMethod = "POST")
    @ApiResponse(code = 200, message = "success")
    @RequestMapping(value = "/import", method = RequestMethod.POST)
    public Object importExcel(MultipartFile file, @RequestParam(value = "channelId")Integer channelId) {
        List<DeviceCirculation> devices = PoiUtils.importEmp2List(file,channelId);
        return "success";
    }

    @ApiOperation(value = "导出设备信息", httpMethod = "GET")
    @ApiResponse(code = 200, message = "success")
    @RequestMapping(value = "/export", method = RequestMethod.GET)
    public ResponseEntity<byte[]> exportExcel(DeviceReq deviceReq) {
        return PoiUtils.exportEmp2Excel(deviceService.listNotPage(deviceReq));
    }

}
